<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="./statics/layui/css/layui.css" rel="stylesheet">
</head>
<body>
<!-- 给容器追加 class="layui-form-pane"，即可显示为方框风格 -->
<form class="layui-form layui-form-pane" action="javaScript:void (0)">
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-block">
            <input type="text" hidden="hidden" value="${sessionScope.user1.id}" name="id" >
            <input type="text" value="${sessionScope.user1.name}" name="uname" autocomplete="off" placeholder="请输入用户名" lay-verify="required" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input type="text" value="${sessionScope.user1.password}" name="upassword" autocomplete="off" placeholder="请输入密码" lay-verify="required" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <button class="layui-btn" lay-submit lay-filter="demo2">提交</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
</form>

<!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
<script src="./statics/layui/layui.js"></script>
<script>
    layui.use(['form'], function(){
        var form = layui.form;
        var layer = layui.layer;
        var $ = layui.jquery;
        // 提交事件
        form.on('submit(demo2)', function(data){
            var field = data.field; // 获取表单字段值
            // 此处可执行 Ajax 等操作
            $.ajax({
                url:"/user",
                data:{
                    "type":"editUser",
                    "id":field.id,
                    "uname":field.uname,
                    "upassword":field.upassword
                },
                type:"POST",
                dataType:"json", //跨平台的数据交互格式
                success:function (res) {
                    if(res.state==200){
                        layer.msg(res.msg,{icon: 1})
                        //增加异步效果
                        setTimeout(function () {
                            var index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe 层的索引
                            parent.layer.close(index); // 再执行关闭
                            parent.location.reload();
                        },2000)

                    }else {
                        layer.alert(res.msg)
                    }
                }
            })




        });
    });
</script>

</body>
</html>